Using Grid ActiveX Control With VB.NET

Introduction

Using the new ActiveX control (MKGrid) with VB.Net, you can read my article about using 
MKGrid control with C#,
With my ActiveX control you can:

  • Bind to database file.
  • Add, Edit and delete records.
  • Use Combo box, Date picker and Check box at any column.
  • Add row, delete row, insert row to unbound grid.
  • Hide column, lock column, resize column and sort column.
  • Save unbound grid after edit it as *.mdb file or *.htm file.
  • After edit cell and leave it the cell will be saved.
  • More properties and methods.
  • Using my AcriveX MKGrid in C# and VB.NET With differences in the names of some properties and its parameters.

GridVB.jpg

When using my ActiveX control (MKGrid) the grid begins with one row as a Data grid control then increases rows one by one after editing the current row.

When you bind the grid with a database file, my ActiveX will look for the Date field; if there are any then put Date picker at the Date column.
Also my ActiveX will look for the Boolean field (Yes, No); if there are any then put Check box at the Boolean column without user intervenes,
this means that the user does not need to specify the type field in this case.

In the following tables you can read about some Methods and some properties as examples.

Method/Property

Explanation

Example

ComboItemsList (ComboCol, ComboList)

Set the List of items [ComboList] to the Combo box at the Column #ComboCol.

MKGrid.ComboItemsList (4, "Apple/Banana/Orange/Melon/Peach/Strawberry")

DeleteRecord

Deletes the current Record from database file.

MKGrid.DeleteRecord

InsertRow

Insert new Row to unbound Grid.

MKGrid.InsertRow

ColumnHidden(number,ColType)

Returns or sets a value indicating whether a specified column is hide.

MKGrid.ColumnHidden(5, True)

set_ColumnType (number, ColType)

Returns or sets the type of control to show in a column.

MKGrid.set_ColumnType (4, KGrid.grdColumnType.colCheckBox)

LoadGridByQuery( MyDataFile, GridSQL)

Populate the grid with query [GridSQL] from the file [MyDataFile].

Dim MyDataFile As String = Application.StartupPath & "\" & "Test.mdb"
Dim MySql As String = "SELECT * FROM Customers"
MKGrid.LoadGridByQuery (MyDataFile, MySql)

LoadGridFromTable( mdbDataFile, mdbTable)

Bind the Grid to the Table [mdbTable] from the database file [mdbDataFile].

Dim MyDataFile As String = StartupPath & "\" & "Test.mdb"
Dim MyTable As String = "Customers"
MKGrid.LoadGridFromTable (MyDataFile, MyTable)

Examples from the Code

About columns:

MKGrid1.Rows = 2 ' number of rows
MKGrid1.Cols = ' number of columns

' Set Header of column:
' 
MKGrid1.set_ColHeaderText(1, "Emp ID")
MKGrid1.set_ColHeaderText(2, "Emp Name")
MKGrid1.set_ColHeaderText(3, "B_Date")
MKGrid1.set_ColHeaderText(4"Salary")
MKGrid1.set_ColHeaderText(5, "Married")
MKGrid1.set_ColHeaderText(6, "City")

About combo box:

Dim strList As String = "Ankara/Berlin/Cairo/London/Los Angeles/Madrid/Marseille/"
' fill CombBox at column #6 with previous list:
MKGrid1.ComboItemsList 
(6, strList)

About Date Picker and Check box:

MKGrid1.set_ColumnType(3, KGrid.grdColumnType.colDateControl) ' Date control at column #3
MKGrid1.set_ColumnType(5, KGrid.grdColumnType.colCheckBox) ' CheckBox at column #5

Remarks

>> When extract the files *.zip You can find:

  • The ActiveX control KGrid.ocx

  • VB.NET Project to test ActiveX.

  • Test_EN.mdb, Test_Ar.mdb and MyMarket.mdb.

  • MKGrid help file.

>> Set my ActiveX "KGrid.ocx" in your program directory, but it is better if you set it in the directory:

"c:\windows\system32\" then register the ActiveX control by run the following line:
regsvr32 
c:\windows\system32\KGrid.ocx

>> To add my ActiveX "MKGrid" control to your form:

- open Components dialog then click Browse
- from its directory or c:\windows\system32\ you can add the ActiveX.

>> You can refer to the help file for all methods and properties. If there are any problems please let me know.

>> I create a project to test my control; I write its code under VisualBasic.Net (2003).

>> If you use VS2008 or VS2010 you can copy the code from the VS2003 project, then paste into your project.

I hope this article is useful and helps you to create your applications. If you have any idea, please tell me.

Up Next
    Ebook Download
    View all
    Learn
    View all